/**
 * walter.pei
 */
package com.koudai.reader.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.koudai.reader.util.Utils;

/**
 * @author walterpei
 * 
 */
public class DatabaseHelper extends SQLiteOpenHelper {

	/**
	 * @param context
	 * @param name
	 * @param factory
	 * @param version
	 * @throws DBException 
	 */
	public DatabaseHelper(Context context, String name, CursorFactory factory,
			int version) throws DBException {
		
		super(context, name, factory, version);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite
	 * .SQLiteDatabase)
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
	    
		if (!Utils.isNullOrEmpty(DBScriptCache.getInstance().getOnCreateScripts())) {
	        for (String sql : DBScriptCache.getInstance().getOnCreateScripts()) {
	        	db.execSQL(sql);
	        }
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite
	 * .SQLiteDatabase, int, int)
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (!Utils.isNullOrEmpty(DBScriptCache.getInstance().getOnUpdateScripts())) {
	        for (String sql : DBScriptCache.getInstance().getOnUpdateScripts()) {
	        	db.execSQL(sql);
	        }
		}
	}
}
